<include file="Public:header" />
<include file="Public:left" />
<form  method="post" enctype="multipart/form-data" id="brandForm">
    <section>
        <h2><strong>编辑通知公告</strong></h2>
        <input type="hidden" id="id" name="id" value="{$data.id}">
        <ul class="ulColumn2">
            <li>
                <span class="item_name" style="width:120px;">通知主题：</span>
                <input type="text" class="textbox textbox_295" name="title" id="title" placeholder="通知主题..." value="{$data.title}"/>
            </li>
            <li>
                <span class="item_name" style="width:120px;">关键字：</span>
                <input type="text" class="textbox textbox_295" name="keyword" id="keyword" placeholder="关键字..." value="{$keyword}"/>
            <li>
            <li>
                <span class="item_name" style="width:120px;">通知部门：</span>
                <input type="text" class="textbox textbox_295" name="department" id="department" placeholder="公告部门..." value="{$data.department}">
            </li>
            <li>
                <span class="item_name" style="width:120px;">通知文号：</span>
                <input type="text" class="textbox textbox_295" name="file_num" id="file_num" placeholder="公告文号..." value="{$data.file_num}">
            </li>
            <li>
                <span class="item_name" style="width:120px;">所属国家：</span>
                <select  class="textbox" name="state" id="state">
                    <option value="-1">--国家--</option>
                    <volist name="state" id="vo">
                        <option value="{$vo.id}" <if condition="$vo.state_name == $data.state">selected</if>>{$vo.state_name}</option>
                    </volist>
                </select>
            </li>
            <li id="select-area">
                <span class="item_name" style="width:120px;">所属地区：</span>
                <select  class="textbox" name="province" id="province">
                    <option value="-1"><if condition="$area[0]==''">--省--<else/>{$area[0]}</if></option>
                    <volist name="province" id="vo">
                        <option value="{$vo.id}">{$vo.name}</option>
                    </volist>
                </select>
                <select class="textbox" name="city" id="city">
                    <option value="-1"><if condition="$area[1]==''">--市--<else/>{$area[1]}</if></option>
                </select>
                <select class="textbox" name="country" id="country">
                    <option value="-1"><if condition="$area[2]==''">--县--<else/>{$area[2]}</if></option>
                </select>
            </li>
            <li>
                <span class="item_name" style="width:120px;">通知时间：</span>
                <input type="text" class="textbox textbox_295" name="take_time" id="take_time" placeholder="通知时间..." value="{$data.take_time|date='Y-m-d H:i:s',###}"/>
            </li>
            <!--<li>-->
                <!--<span class="item_name" style="width:120px;">申报时间：</span>-->
                <!--<input type="text" class="textbox textbox_295" name="add_content" id="add_content" placeholder="申报时间..." value="{$data.add_content}"/>-->
            <!--</li>-->
            <li>
                <span class="item_name" style="width:120px;">过期时间：</span>
                <input type="text" class="textbox textbox_295" name="over_time" id="over_time" placeholder="过期时间..." value="{$data.over_time|date='Y-m-d H:i:s',###}"/>
            </li>
            <li>
                <span class="item_name" style="width:120px;">是否发布：</span>
                <select name="is_display" id="is_display">
                    <if condition="$data['is_display'] == 1">
                        <option value="1" selected>发布</option>
                        <option value="0">不发布</option>
                        <else />
                        <option value="1">发布</option>
                        <option value="0" selected>不发布</option>
                    </if>
                </select>
            </li>
            <li>
                <span class="item_name" style="width:120px;">新闻内容：</span>
                <script id="editor" name="content" type="text/plain" style="width:700px;height:300px;margin-left:125px; margin-top:-12px;">{$data['content']|htmlspecialchars_decode}</script>
            </li>
            <li>
                <span class="item_name" style="width:120px;">预览附件：</span>
                <input type="file" class="textbox textbox_295" name="file" id=""  value=""/>&nbsp;&nbsp;注：只能上传PDF文件
                <input type="hidden" id="file_id" value="{$data.file_id}">
            </li>
            <li>
                <span class="item_name" style="width:120px;">下载文件：</span>
                <input type="file" class="textbox textbox_295" name="down_file" id=""  value=""/>&nbsp;&nbsp;
                <input type="hidden" id="down_id" value="{$data.down_id}">
            </li>
            <li>
                <span class="item_name" style="width:120px;"></span>
                <input type="button" class="link_btn" value="提交"/>
            </li>
        </ul>
    </section>
</form>
<!--tabStyle-->
<script type="text/javascript" src="__STATIC__/laydate/laydate.js"></script>
<script>
    laydate.render({
        elem: '#create_time' //指定元素
        ,type:'datetime'
    });
    laydate.render({
        elem: '#take_time' //指定元素
        ,type:'datetime'
    });
    laydate.render({
        elem: '#over_time' //指定元素
        ,type:'datetime'
    });
</script>
<script type="text/javascript">
    $(document).ready(function(){
        //tab
        $(".admin_tab li a").click(function(){
            var liindex = $(".admin_tab li a").index(this);
            $(this).addClass("active").parent().siblings().find("a").removeClass("active");
            $(".admin_tab_cont").eq(liindex).fadeIn(150).siblings(".admin_tab_cont").hide();
        });

        $(".link_btn").click(function(){

            if($("#title").val()==""){
                layer.alert("通知主题不能为空!");
                return false;
            }

//            if($("#keyword").val()==""){
//                layer.alert("关键字不能为空!");
//                return false;
//            }
//
//            if($("#department").val()==""){
//                layer.alert("通知部门不能为空!");
//                return false;
//            }
//
//
//            if($("#file_num").val()==""){
//                layer.alert("通知文号不能为空!");
//                return false;
//            }

//            if($("#province").val()=="-1" ||$("#city").val()=="-1" || $("#country").val()=="-1"){
//                layer.alert("地区不能为空!");
//                return false;
//            }
//            console.log($("#city").find("option:selected"));
//            if($("#take_time").val()==""){
//                layer.alert("通知时间不能为空!");
//                return false;
//            }
//
//            if($("#over_time").val()==""){
//                layer.alert("过期时间不能为空!");
//                return false;
//            }
//
//            if($("#add_content").val()==""){
//                layer.alert("申报时间不能为空");
//                return false;
//            }
//
//            if(ue.getContent()==""){
//                layer.alert("内容不能为空!");
//                return false;
//            }

            var formData = new FormData();
            var title = $('input[name="title"]').val();
            var keyword = $('input[name="keyword"]').val();
            var department = $('input[name="department"]').val();
            var file_num = $('input[name="file_num"]').val();
            if($("#state").val()=="-1"){
                var state = '';

            }else{
                var state = $('select[name="state"]').find("option:selected").text();
            }
            if($("#province").val()=="-1"){
                if($('select[name="province"]').find("option:selected").text() == '--省--'){
                    var province = '';
                }else{
                    var province = $('select[name="province"]').find("option:selected").text();
                }
            }else{
                var province = $('select[name="province"]').find("option:selected").text();
            }

            if($("#city").val()=="-1"){
                if($('select[name="city"]').find("option:selected").text() == '--市--'){
                    var city = '';
                }else{
                    var city = $('select[name="city"]').find("option:selected").text();
                }

            }else{
                var city = $('select[name="city"]').find("option:selected").text();
            }

            if($("#country").val()=="-1"){
                if($('select[name="country"]').find("option:selected").text() == '--县--'){
                    var country = '';
                }else{
                    var country = $('select[name="country"]').find("option:selected").text();
                }

            }else{
                var country = $('select[name="country"]').find("option:selected").text();
            }
//            var add_content = $('input[name="add_content"]').val();
            var take_time = $('input[name="take_time"]').val();
            var over_time = $('input[name="over_time"]').val();
            var is_display = $('select[name="is_display"]').val();
            var content = ue.getContent();
            var id = $('input[name="id"]').val();
            var fid = $('#file_id').val();
            var file = $(':file')[0].files[0];
            if(file){
                var file_name = $(':file')[0].files[0].name;
            }

            var down_id = $('#down_id').val();
            var down_file = $(':file')[1].files[0];
            if(down_file){
                var down_file_name = $(':file')[1].files[0].name;
            }

//            console.log(city);

            formData.append('title',title);
            formData.append('keyword',keyword);
            formData.append('department',department);
            formData.append('file_num',file_num);
            formData.append('state', state);
            formData.append('province',province);
            formData.append('city',city);
            formData.append('country',country);
//            formData.append('add_content',add_content);
            formData.append('take_time',take_time);
            formData.append('over_time',over_time);
            formData.append('is_display',is_display);
            formData.append('content',content);
            formData.append('file',file);
            formData.append('file_name',file_name);
            formData.append('id', id);
            formData.append('fid',fid);
            formData.append('down_file',down_file);
            formData.append('did',down_id);
            formData.append('down_file_name',down_file_name);
//console.log(formData);
            $.ajax({
                url:"{:url('Notice/add')}",
                type:'POST',
                data:formData,
                async:false,
                processData:false,
                contentType:false,
                success:function(result){
//                    console.log(result.msg)
                    if(result.code == '0'){
                        layer.alert(result.msg);
                    }else{
                        layer.alert(result.msg, {
                                    btn: ['确定']
                                },
                                function (index, item) {
                                    location.href = result.url;
                                });
                    }
                }

            });

        });

    });
</script>

<script type="text/javascript">

    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
    var ue = UE.getEditor('editor');


    function isFocus(e){
        alert(UE.getEditor('editor').isFocus());
        UE.dom.domUtils.preventDefault(e)
    }
    function setblur(e){
        UE.getEditor('editor').blur();
        UE.dom.domUtils.preventDefault(e)
    }
    function insertHtml() {
        var value = prompt('插入html代码', '');
        UE.getEditor('editor').execCommand('insertHtml', value)
    }
    function createEditor() {
        enableBtn();
        UE.getEditor('editor');
    }


</script>
<script type="text/javascript">
    // change事件
    $('#select-area select').change(function () {
//         console.log($(this).val());
        var id = $(this).val();
        var that = $(this);
        $.ajax({
            url : "{:url('Publicity/getAreas')}",
            type:'POST',
            data:{id:id,},
            success:function(result){
                // console.log(that);
                // console.log(that.next());
                // console.log(that.next().size());
                if(that.next().size() == 1){
                    that.next()[0].length = 1;
                    that.next().append(result.msg);
                }

            }
        });
    });

</script>
</div>
</section>
</body>
</html>
